package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.service.IGymCoachService;
import com.ruoyi.system.service.IGymMemberService;
import com.ruoyi.system.service.IGymRegionService;
import com.ruoyi.system.service.ISysConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GymMember;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健身房会员Controller
 * 
 * @author ruoyi
 * @date 2024-04-22
 */
@Controller
@RequestMapping("/system/member")
public class GymMemberController extends BaseController
{
    private String prefix = "system/member";

    @Autowired
    private IGymMemberService gymMemberService;

    @Autowired
    private IGymCoachService coachService;

    @Autowired
    private IGymRegionService regionService;

    @RequiresPermissions("system:member:view")
    @GetMapping()
    public String member()
    {
        return prefix + "/member";
    }

    /**
     * 查询健身房会员列表
     */
    @RequiresPermissions("system:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GymMember gymMember)
    {
        startPage();
        List<GymMember> list = gymMemberService.selectGymMemberList(gymMember);
        return getDataTable(list);
    }

    /**
     * 导出健身房会员列表
     */
    @RequiresPermissions("system:member:export")
    @Log(title = "健身房会员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GymMember gymMember)
    {
        List<GymMember> list = gymMemberService.selectGymMemberList(gymMember);
        ExcelUtil<GymMember> util = new ExcelUtil<GymMember>(GymMember.class);
        return util.exportExcel(list, "健身房会员数据");
    }

    /**
     * 新增健身房会员
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("coaches", coachService.selectGymCoachAll());
        mmap.put("regiones", regionService.selectGymRegionAll());
        return prefix + "/add";
    }

    /**
     * 新增保存健身房会员
     */
    @RequiresPermissions("system:member:add")
    @Log(title = "健身房会员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GymMember gymMember)
    {
        return toAjax(gymMemberService.insertGymMember(gymMember));
    }

    /**
     * 修改健身房会员
     */
    @RequiresPermissions("system:member:edit")
    @GetMapping("/edit/{memberId}")
    public String edit(@PathVariable("memberId") Long memberId, ModelMap mmap)
    {
        GymMember gymMember = gymMemberService.selectGymMemberByMemberId(memberId);
        mmap.put("coaches", coachService.selectGymCoachAll());
        mmap.put("regiones", regionService.selectGymRegionAll());
        mmap.put("gymMember", gymMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存健身房会员
     */
    @RequiresPermissions("system:member:edit")
    @Log(title = "健身房会员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GymMember gymMember)
    {
        return toAjax(gymMemberService.updateGymMember(gymMember));
    }

    /**
     * 删除健身房会员
     */
    @RequiresPermissions("system:member:remove")
    @Log(title = "健身房会员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gymMemberService.deleteGymMemberByMemberIds(ids));
    }
}
